package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Permission;
import com.itany.pojo.Role;
import com.itany.service.PermissionService;
import com.itany.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import utils.AjaxResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author：汤小洋
 * Date：2019-09-25 上午10:04
 * Description：<描述>
 */
@Controller
@RequestMapping("/role")
public class RoleController {


    @Autowired
    private RoleService roleService;
    @Autowired
    private PermissionService permissionService;


    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows, Role role){

        System.out.println(role+"11111111111111111111111");
        Map<String,Object> map = new HashMap<String, Object>();
        PageInfo<Role> info = roleService.findAllBook(page, rows,role);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }

    @RequestMapping("findAllPermission")
    @ResponseBody
    public List<Permission> findAll(){
        List<Permission> permissions= permissionService.findPermission();

        return permissions;
    }



    @RequestMapping("modifyRole")
    @ResponseBody
    public AjaxResult modifyRole(Role role, @RequestParam("ids")String ids){

        String[] split = ids.split(",");

        roleService.modifyRole(role,split);


        return AjaxResult.isOk();
    }

    /**
     * 角色删除
     * @param id
     * @return
     */
    @RequestMapping("removeRole")
    @ResponseBody
    public AjaxResult removeRole(Integer id){

        roleService.removeRoleById(id);

        return AjaxResult.isOk();
    }


} 